﻿// <copyright file="MainPage.xaml.cs" company="Microsoft Corporation">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-03-03</date>
// <summary>Silverlight page</summary>

namespace DemoNYTimes
{
    using System.Windows;
    using System.Windows.Controls;
    using NYTimes;
    using NYTimes.Data;

    /// <summary>
    /// Silverlight page
    /// </summary>
    public partial class MainPage : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the MainPage class.
        /// </summary>
        public MainPage()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Image failed event handler
        /// </summary>
        /// <param name="sender">the image that failed to load its image</param>
        /// <param name="e">the exception routed event arguments</param>
        private void OnImageFailed(object sender, ExceptionRoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(e.ErrorException.Message);
        }

        /// <summary>
        /// Navigate to a page
        /// </summary>
        /// <param name="sender">the navigation</param>
        /// <param name="e">the selection changed event arguments</param>
        private void OnPageSelected(object sender, SelectionChangedEventArgs e)
        {
            if (this.PageList.SelectedItem == null)
            {
                return;
            }

            var demoPage = this.PageList.SelectedItem as DemoPage;

            this.frame.Navigate(demoPage.Url);
        }
    }
}
